<template>
  <div class="CateList-header">
    <div class="back">
      <router-link to="/home">
        <van-icon
          name="arrow-left"
          class="goback"
          color="#fff"
          size="0.2rem"
          v-if="backFlag"
        />
      </router-link>
    </div>
    <div class="header-title">
      <div class="title">{{ title }}</div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, reactive, onMounted, watch, toRefs } from "vue";
import { useRoute } from "vue-router";

export default defineComponent({
  setup() {
    const route = useRoute();
    const state: any = reactive({
      title: "",
      backFlag: false,
    });
    const backArr: any = [];
    const checkback = () => {
      const currentPath = route.path;
      const f = backArr.some((item: any) => currentPath.indexOf(item) !== -1);
      if (f) {
        state.backFlag = false;
      } else {
        state.backFlag = true;
      }
    };
    onMounted(() => {
      checkback();
      if (route.meta?.title) {
        state.title = route?.meta?.title;
      } else {
        state.title = route?.query?.title;
      }
    });
    watch(route, () => {
      checkback();
      if (route.meta?.title) {
        state.title = route?.meta?.title;
      } else {
        state.title = route?.query?.title;
      }
    });
    return {
      ...toRefs(state),
    };
  },
});
</script>

<style lang="stylus" scoped>
.CateList-header {
  position:fixed;
  top:0;
  height: 0.44rem;
  width: 100%;
  display: flex;
  z-index: 60;
  background-color: #fe3c35;
  overflow: hidden

  .back {
    position: fixed;
    top: 0;
    width: 0.28rem;
    height: 0.28rem;
    z-index: 100;

    a {
      .goback {
        position: absolute;
        top: 0;
        width: 0.28rem;
        height: 0.28rem;
        z-index: 100;
        margin: 0.1rem 0.05rem;
      }
    }
  }

  .header-title {
    display: flex;
    height: 100%;
    width: 100%;
    align-items: center;
    text-align: center;

    .title {
      flex: 1;
      color: white;
      font-size: 0.17rem;
    }
  }
}
</style>
